package com.yinet.web.controller.touchscreen;

import com.yinet.common.config.Global;
import com.yinet.common.config.ServerConfig;
import com.yinet.common.core.controller.BaseController;
import com.yinet.common.core.page.TableDataInfo;
import com.yinet.common.utils.QRCodeUtils;
import com.yinet.common.utils.ServletUtils;
import com.yinet.system.domain.TouchScreenGuidance;
import com.yinet.system.domain.TouchScreenNotice;
import com.yinet.system.service.TouchScreenGuidanceService;
import com.yinet.system.service.TouchScreenHelpInfoService;
import com.yinet.system.service.TouchScreenNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author ruoyi
 */
@Controller
@RequestMapping("/touchscreen")
public class BaseWebController extends BaseController {
    static String touchIndex = "touchscreen/web/";
    @Autowired
    private TouchScreenHelpInfoService touchScreenHelpInfoService;
    @Autowired
    private TouchScreenNoticeService touchScreenNoticeService;
    @Autowired
    private TouchScreenGuidanceService touchScreenGuidanceService;

    /**
     * 首页
     *
     * @return
     */
    @GetMapping(value = "/index")
    public String Index() {
        return touchIndex + "index";
    }

    /**
     * 中心介绍
     *
     * @return
     */
    @GetMapping(value = "/jieshao")
    public String GetInfo(Model model) {
        model.addAttribute("helpInfo", touchScreenHelpInfoService.selectHelpInfoLimit(1));
        return touchIndex + "jieshao";
    }

    /**
     * 办件查询
     *
     * @return
     */
    @GetMapping(value = "/search")
    public String Search() {
        return touchIndex + "search";
    }

    /**
     * 办事指南
     *
     * @return
     */
    @GetMapping(value = "/nan")
    public String GetHelp(Model model) {
        List<TouchScreenGuidance> guidanceList = touchScreenGuidanceService.selectParentGuidanceList();
        model.addAttribute("guidanceList", guidanceList);
        return touchIndex + "nan";
    }

    /**
     * 公示公告
     *
     * @return
     */
    @GetMapping(value = "/notice")
    public String GetNotice() {
        return touchIndex + "notice";
    }

    /**
     * 公示公告列表
     *
     * @return
     */
    @PostMapping("/notice/list")
    @ResponseBody
    public TableDataInfo GetNoticeList() {
        startPage();
        List<TouchScreenNotice> touchScreenNotices = touchScreenNoticeService.selectNoticeList();
        return getDataTable(touchScreenNotices);
    }

    /**
     * 公示公告详细信息
     *
     * @return
     */
    @GetMapping(value = "/notice/{id}")
    public String GetNoticeInfo(@PathVariable("id") String id, Model model) {
        TouchScreenNotice touchScreenNotice = touchScreenNoticeService.selectNoticeById(id);
        model.addAttribute("noticeinfo", touchScreenNotice);
        return touchIndex + "noticeinfo";
    }

    /**
     * 实时叫号
     *
     * @return
     */
    @GetMapping(value = "/hao")
    public String CallNum() {
        return touchIndex + "hao";
    }

    /**
     * 办件统计
     *
     * @return
     */
    @GetMapping(value = "/tong")
    public String 统计() {
        return touchIndex + "tong";
    }

    /**
     * 办事指南列表
     */
    @GetMapping(value = "/guidanceList/{id}/{type}")
    public String guidanceList(@PathVariable("id") Long id, @PathVariable("type") String type, Model model) {
        List<TouchScreenGuidance> guidanceList = touchScreenGuidanceService.selectGuidanceListByIdAndType(id, type);
        model.addAttribute("guidanceList", guidanceList);
        return touchIndex + "list";
    }

    /**
     * 查看文档
     *
     * @return
     */
    @GetMapping(value = "/guidanceList/viewdoc/{id}")
    public String ViewDoc(@PathVariable("id") Long id, Model model) throws IOException {
        TouchScreenGuidance guidance = touchScreenGuidanceService.selectGuidanceById(id);
        String domain = ServerConfig.getDomain(ServletUtils.getRequest());
        String qrUrl = domain + guidance.getDocUrl();
        String s = QRCodeUtils.generalQRCode(qrUrl);
        guidance.setQrCode(s);
        model.addAttribute("guidance", guidance);
        return touchIndex + "viewdoc";
    }


    /**
     * 页头
     *
     * @return
     */
    @GetMapping(value = "/header")
    public String GetHeader() {
        return touchIndex + "tsheader";
    }

    /**
     * 页脚
     *
     * @return
     */
    @GetMapping(value = "/bottom")
    public String GetFooter() {
        return touchIndex + "bottom";
    }

    /**
     * 获取站点属性
     *
     * @return
     */
    @GetMapping(value = "/getsitefav")
    @ResponseBody
    public String GetSiteFav() {
        String site = Global.getSite();
        String src = "/touchscreenstyle/images/logo" + site + ".png";
        return src;
    }
}
